package com.example.sampleworks.ui;

import com.example.sampleworks.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MenuList extends Activity {

	Context context;

	ListView lstMenu;

	ArrayAdapter<String> adapter;
	String[] menus = { "ListItems" ,"ImageDisplay" ,"ListViewAndroidEx" ,"ImageTextListViewActivity" };
	Intent intent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		context=this;
		
		intializeUI();
		
		setListner();
		setDataValue();
		
	}

	private void intializeUI() {

		lstMenu = (ListView) findViewById(R.id.lstMenu);

	}

	private void setListner() {

		lstMenu.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				
				
				Class classname = null;
				
				try {
					 classname=Class.forName("com.example.sampleworks.ui."+menus[position]);
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				Toast.makeText(context, "Position "+position, Toast.LENGTH_SHORT).show();
				
				intent =new Intent(context,classname);
				
				startActivity(intent);
				
			}
		});
		
	}

	private void setDataValue() {

		adapter = new ArrayAdapter<String>(context,
				android.R.layout.simple_list_item_1, menus);
		lstMenu.setAdapter(adapter);

	}

}
